package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.rm.zeyou.entity.Technician;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.TechnicianService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.util.login.TechnicianLoginUtil;
import com.rm.zeyou.vo.request.*;
import com.rm.zeyou.vo.response.SelectTechnicianDetailResponseVo;
import com.rm.zeyou.vo.response.SelectTechnicianListResponseBaseVo;
import com.rm.zeyou.vo.response.TechnicianPersonalCenterResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * <p>
 * 技师表 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:09
 */
@Api(tags = "技师相关")
@RestController
@RequestMapping("/api/technician")
public class TechnicianController {
    @Resource
    private TechnicianService technicianService;
    @Resource
    private TechnicianLoginUtil technicianLoginUtil;
    @Resource
    private LoginUtil loginUtil;

    @ApiOperation(value = "技师密码登录")
    @PostMapping("technicianPassLogin")
    public ApiRestResponse<Map<String, String>> technicianPassLogin(@RequestBody TechnicianPassLoginVo loginVo) {
        return technicianService.technicianPassLogin(loginVo);
    }

    @ApiOperation("技师H5绑定微信")
    @PostMapping("technicianH5BindWx")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse technicianH5BindWx() throws UnsupportedEncodingException {
        Technician technician = technicianLoginUtil.getTechnician();
        return technicianService.technicianH5BindWx(technician);
    }

    @ApiOperation("技师APP绑定微信")
    @PostMapping("technicianAPPBindWx")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse technicianAPPBindWx(@RequestBody UserBindTelVo bindTelVo) {
        Technician technician = technicianLoginUtil.getTechnician();
        return technicianService.technicianAPPBindWx(technician,bindTelVo);
    }

    @ApiOperation(value = "查询技师列表")
    @PostMapping("selectTechnicianList")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<SelectTechnicianListResponseBaseVo> selectTechnicianList(@RequestBody SelectTechnicianListVo requestVo) {
        User user = loginUtil.getUser();
        return technicianService.selectTechnicianList(user.getId(),requestVo);
    }

    @ApiOperation(value = "查询技师详情")
    @PostMapping("selectTechnicianDetail")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<SelectTechnicianDetailResponseVo> selectTechnicianDetail(@RequestBody SelectTechnicianListVo requestVo) {
        User user = loginUtil.getUser();
        return technicianService.selectTechnicianDetail(user.getId(), requestVo);
    }

    @ApiOperation(value = "根据项目查询技师列表")
    @PostMapping("selectTechnicianListByItemId")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<SelectTechnicianListResponseBaseVo> selectTechnicianListByItemId(@RequestBody SelectTechnicianListVo requestVo) {
        User user = loginUtil.getUser();
        return technicianService.selectTechnicianListByItemId(user.getId(), requestVo);
    }


    @ApiOperation(value = "技师修改密码验证")
    @PostMapping("technicianReplacePassVerify")
    public ApiRestResponse<Void> technicianUpdatePasVerify(@RequestBody TechnicianReplacePassVo replaceVo) {
        return technicianService.technicianUpdatePasVerify(replaceVo);
    }

    @ApiOperation(value = "技师修改密码")
    @PostMapping("technicianReplacePass")
    public ApiRestResponse<Integer> technicianReplacePass(@RequestBody TechnicianReplacePassVo replaceVo) {
        return technicianService.technicianReplacePass(replaceVo);
    }


    @ApiOperation(value = "技师个人中心")
    @GetMapping("technicianPersonalCenter")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse<TechnicianPersonalCenterResponseVo> technicianPersonalCenter() {
        Technician technician = technicianLoginUtil.getTechnician();
        return technicianService.technicianPersonalCenter(technician);
    }

    @ApiOperation(value = "技师上/下线")
    @PostMapping("technicianOnline")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse<Integer> technicianOnline() {
        Technician technician = technicianLoginUtil.getTechnician();
        return technicianService.technicianOnline(technician);
    }

    @ApiOperation(value = "技师退出登陆下线")
    @PostMapping("technicianLoginOut")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse<Integer> technicianLoginOut() {
        Technician technician = technicianLoginUtil.getTechnician();
        return technicianService.technicianLoginOut(technician);
    }

    @ApiOperation(value = "技师更换手机号验证")
    @PostMapping("technicianUpdateTelVerify")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse<Void> technicianUpdateTelVerify(@RequestBody TechnicianUpdateTelVo updateVo) {
        Technician technician = technicianLoginUtil.getTechnician();
        return technicianService.technicianUpdateTelVerify(technician,updateVo);
    }

    @ApiOperation(value = "技师更换手机号")
    @PostMapping("technicianUpdateTel")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse<Integer> technicianUpdateTel(@RequestBody TechnicianUpdateTelVo updateVo) {
        Technician technician = technicianLoginUtil.getTechnician();
        return technicianService.technicianUpdateTel(technician,updateVo);
    }

    @ApiOperation(value = "技师修改个人信息")
    @PostMapping("technicianUpdate")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse<Integer> technicianUpdate(@RequestBody TechnicianUpdateVo updateVo) {
        Technician technician = technicianLoginUtil.getTechnician();
        return technicianService.technicianUpdate(technician,updateVo);
    }

}
